<!--  项目在线评审列表 -->
<template>
  <RkContainer :isFooter="false" :isAside=false>
    <template #header_left>
      <RkButtonGroup :options="json_online_button"
        v-model="queryParams.wfStatus"
        @click="handleSearch" />
    </template>
    <template #header_right>
      <el-button v-if="queryParams.wfStatus=='001'"
        type="primary"
        @click="handleOpenRecord('audit','评审')">评审</el-button>
      <el-button v-if="queryParams.wfStatus=='002'" type="primary"
        @click="handleOpenRecord('edit', '修改')">修改</el-button>
      <el-button v-if="queryParams.wfStatus=='002'"
        @click="handleOperation('delete', '删除')">确认</el-button>
    </template>
    <template #main>
      <rk-condition>
        <template #content>
          <rk-grid ref="grProjApply"
            title="项目在线评审"
            dataUrl="/reviewtask/page"
            boxConfig
            :params="queryParams"
            :columns="tableColumns">
            <template #toolbar_title_buttons>
              <el-input v-model="queryParams.mhcx"
                placeholder="请输入项目名称"
                class="mr-15px w-200px"
                @input="handleSearch"
                clearable>
              </el-input>
            </template>
            <template #bondType="{ row }">
              <span class="mx-1">
                {{ COMMON_BOND_TYPES.options[row.bondTypeCode].echo }}
              </span>
            </template>
          </rk-grid>
        </template>
      </rk-condition>
    </template>
  </RkContainer>
  <OperationLog ref="OperationLogRef" />
</template>
<script setup>
import { json_online_button } from '@/common/button-data.js'
import { COMMON_BOND_TYPES, COMMON_AMOUNT_UNIT } from '@/enums/enums-common.js'
import { WF_TASK_SEND_AUDIT, WF_TASK_CANCEL } from '@/common/cons-common.js'
import { RkConfirmBox } from '@/components/message-box/index.js'
import { deleteReserveProject, reserveProHandleTask } from '@/api/api-project'
import OperationLog from '@/components/log/OperationLog.vue'

//新增项目参数
const proId = ref('')
// 设计表单ID
const formId = ref('A0C89DA422604CD6B7A6EBE20D0A3761')
// 流程标识
const processKey = ref('PRO_CBK')

const OperationLogRef = ref(null)
const { appContext } = getCurrentInstance();
const globalProxy = appContext.config.globalProperties;
const emit = defineEmits(['agNodeClick'])
const grProjApply = ref('')
let leaf = ref(false)
// 查询参数
let queryParams = reactive({
  wfStatus: '001',
  status: undefined,
  mhcx: undefined,
  bondTypeCode: 1,    // 债券类型测试数据 1、一般 2、专项
  nodeId: 'node_1',  //填报测试数据
  processKey: 'PRO_CBK', //测试数据
  adCode: '2300', //'321005'
  agCode: undefined,
  agId: undefined,
  dw: 2
})

// 基本信息
const baseInfo = reactive({
  // 选中项目ID
  proId: '',
  // 选中区划编码
  adCode: '2300',
  // 单位ID
  agId: '',
  // 选中单位编码
  agCode: '',
  // 单位名称
  agName: '',
  proSource: '2'
})
const tableColumns = ref([
  { field: 'setupYear', title: '地区', width: 180 },
  { field: 'agencyName', title: '单位', width: 150 },
  { field: 'fundInvestAreaCode', title: '项目编码', width: 250 },
  { field: 'totalBudget', title: '项目名称', width: 200, align: 'right' },
  { field: 'proStatusName', title: '项目投向领域', width: 150 },
  { field: 'startDate', title: '项目类型', width: 150 },
  { field: 'endDate', title: '评审报告', width: 150 },
  { field: 'remark', title: '备注', width: 120 },
])

/**查询 */
const handleSearch = () => {
  grProjApply.value.searchEvent()
}
//送审、撤销送审、删除
const handleOperation = async (buttonType, textName) => {
  const seleRows = grProjApply.value.getCheckboxRecords()
  if (seleRows.length == 0 || !seleRows) {
    globalProxy.$message({ message: `请至少选择一条数据进行${textName}！`, type: "warning" });
    return;
  }
  //获取选中数据
  const ProId = []
  const TaskId = []
  const ApplyId = []
  seleRows.forEach(element => {
    ApplyId.push(element.applyId)
    ProId.push(element.proId)
    TaskId.push(element.taskId)
  });
  const applyIds = ApplyId.join(',')
  const proIds = ProId.join(',')
  const taskIds = TaskId.join(',')
  if (buttonType == 'cancel') { //撤销送审
    const deleteParams = { applyIds, taskIds, proIds, nodeId: queryParams.nodeId, taskType: WF_TASK_CANCEL.value }
    // const result = await reserveProHandleTask(deleteParams)
    // const { data, code, msg } = result
    // if (code === 200) {
    //   globalProxy.$message({ message: `${textName}成功！`, type: "success" });
    //   handleSearch()
    // } else {
    //   globalProxy.$message({ message: `${msg}`, type: "error" });
    // }
  }
}

const handleOpenRecord = (buttonType, textName) => {
  const seleRows = grProjApply.value.getCheckboxRecords()
  if (seleRows.length == 0 || !seleRows || seleRows.length > 1) {
    globalProxy.$message({ message: "请选择一条数据！", type: "warning" });
    return;
  }
  //修改
  if (buttonType == 'edit') {
    // handleEditProj(seleRows[0].proId)
  }
  if(buttonType == 'audit'){
    
  }
}
</script>

<style lang="scss" scoped>
.mr-15px {
  margin-right: 15px;
  &:last-child {
    margin-right: 0;
  }
}
.w-200px {
  width: 200px;
}
</style>